package com.wei.controller;

import com.wei.service.DailyService;
import com.wei.utils.R;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Map;

/**
 * @author wjx
 * @ClassName DailyController
 * @description: TODO
 * @date 2022-12-05 04:08
 * @version: 1.0
 */
@RestController
@RequestMapping("/edusta/count")
public class DailyController {

    @Autowired
    private DailyService statisticsDailyService;

    /**
     * 远程调用接口实现功能：把某一天的注册人数加入数据库表中
     *
     * @param day
     * @return
     */
    @PostMapping("/createStatisticsByDate/{day}")
    public R createStatisticsByDate(@PathVariable String day) {

        statisticsDailyService.createStatistics(day);

        return R.ok();
    }

    /**
     * 根据 类型、时间 返回图表显示的数据
     *
     * @param type
     * @param begin
     * @param end
     * @return
     */
    @GetMapping("/getChartData/{type}/{begin}/{end}")
    public R getChartData(@PathVariable String type,
                          @PathVariable String begin,
                          @PathVariable String end) {

        Map<String, Object> map = statisticsDailyService.createChartData(type, begin, end);

        return R.ok().data("map", map);
    }
}
